
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$title="Thêm danh muc bài viết";


require '../layout/headeradmin.inc';

$title="";
$cate_id=0;
$images="";
$introtext="";
$fulltext="";
$chk=0;
$metakey="";
$create_by=1;
$modified_by=1;
$checkin=0;

if(isset($_POST['them_bv']))
{
    
   $title=  trim($_POST['title']);
   $cate_id=trim($_POST['cate_id']);
        
  
   $introtext=  trim(addslashes($_POST['introtext']));
    $fulltext= trim( addslashes($_POST['fulltext']));;
   // echo stripslashes($fulltext);
    if(isset($_POST['chk']))
          $chk=1;
     if(isset($_POST['checkin']))
          $checkin=1;
   
    $metakey= trim(addslashes($_POST['metakey']));
    $create_by=1;
    $modified_by=1;
    
    
    
     $images=$_POST['Image'];
//    $images=str_replace("\/nhahangtaybac","..",$images);
    
    
//if($_FILES['file']['error']>0)
//{
////    echo 'Error:'.$_FILES['file']['error'];
//}
// else {
//    if(file_exists('../upload/'.$_FILES['file']['name']))
//            unlink('../upload/'.$_FILES["file"]["name"]);
//
//     $images=$_FILES['file']['name']; 
//     move_uploaded_file($_FILES["file"]["tmp_name"],
//      "../uploadimages/" . $_FILES["file"]["name"]);
//  
// }
     if(get_magic_quotes_gpc())
    {
        $title=  trim(addslashes($_POST['title']));
        $cate_id=trim(addslashes($_POST['cate_id']));

      
        $introtext=  trim(addslashes($_POST['introtext']));
        $fulltext=trim(addslashes($_POST['fulltext']));;
        if(isset($_POST['chk']))
             $chk=1;
		if(isset($_POST['checkin']))
          $checkin=1;
       
        $metakey= trim(mysqli_real_escape_string($_POST['metakey']));
   
    }
   //  $k->insertArticle($title,$introtext,$fulltext,$cate_id,$create_by,$modified_by,$chk,$images,$metakey);
   //  
   //  
    
    $db=  mysqli_connect("localhost", "root", "", "datashop");
     mysqli_set_charset($db, "utf8");
 $create=date("Y-m-d");
  $modified=date("Y-m-d");
           $sql = "INSERT INTO `content`(`title` , `introtext` , `fulltext` , `catid` , `created` , `created_by` , `modified` , `modified_by` , `Active` , `images` , `metakey`,`checkin` )"
                               ." VALUES ('$title','$introtext','$fulltext','$cate_id','$create','$create_by','$modified','$modified_by','$chk','$images','$metakey','$checkin')";
        mysqli_query($db, $sql) or die(mysqli_error($db)) ;
        
  header("Location:ckeditor.php");
}
 else {
    

?>
<!--<script src="../plugin/ckeditor_4.4.4_full/ckeditor/ckeditor.js" type="text/javascript"></script>-->

<script src="../scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script src="../plugin/ckeditor/ckeditor.js" type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="../plugin/ckfinder/ckfinder.js" type="text/javascript"></script>
<script src="../plugin/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript">
        function BrowseServer() {
            var finder = new CKFinder();
         //   finder.basePath = '../uploadimages/';
            finder.selectActionFunction = SetFileField;
            finder.popup();
        }
        function SetFileField(fileUrl) {
            document.getElementById('Image').value = fileUrl;
        }
    </script>
<script>
    $( document ).ready( function() {
	$( 'textarea#fulltext' ).ckeditor(function(){}, {
                        uiColor: '#14B8C4',language: 'vi'
                    } );
} );
</script>

<?php
//echo $_SERVER['DOCUMENT_ROOT'];
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
    <fieldset>
        <legend><text>Bài viết</text></legend>
        <table id="t-adduser">
            <tbody>
                <tr>
                    <td><label>Tiêu đề</label></td>
                    <td><input type="text" id="title" name="title"></td>
                </tr>
                <tr>
                    <td><label>Metakey</label></td>
                    <td><input type="text" id="metakey" name="metakey"></td>
                </tr>
<!--                 <tr>
                    <td><label>ckeditor</label></td>
                    <td><textarea row="4" cols="100" class="ckeditor" name="eddd" ></textarea></td>
                </tr>-->
                <tr>
                    <td><label>Danh mục</label></td>
                    <td>
                        
                        <?php 
//                        echo mysqli_num_rows($k->getCateParent());
//                        if(mysqli_num_rows($k->getCateParent())>0)
//                        {
//   
                            ?>
                            <select id="se" name="cate_id">
                           
                                <?php 
                                
                                    $data=$k->getCateParent();
                                    echo mysqli_num_rows($data);
                                   while ($row = mysqli_fetch_array($data)) {
                                        
                                 
                                
                                
                                ?>
                                <option value="<?php echo $row['id'];?>"><?php echo $row['name_cate']; ?></option>
                          
                            
                        
                        <?php 
//                           }
                        }
// else {
//     
// }
                        ?>
                                </select>
                    </td>
                </tr>
                 <tr>
                    <td><label>Ảnh đại diện</label></td>
<!--                    <td><input type="file" name="file" id="file"></td>-->
                    <td>
                        <input type="text" name="Image" id="Image" value="" />
    <input type="button" value="Chọn Ảnh ..." onclick="BrowseServer();"/>
                    </td>
                </tr>
                 <tr>
                    <td><label>Thông tin</label></td>
                    <td><textarea row="4" cols="100"  id="introtext" name="introtext" ></textarea></td>
                </tr>
                <tr>
                    <td><label>Nội dung</label></td>
                    <td> <textarea cols="80" id="fulltext" name="fulltext" rows="10">
			
		</textarea>
                        </td>   
		
                </tr>
                <tr>
                    <td><label>Hiện</label></td>
                    <td><input type="checkbox" name="chk" id="chk"></td>
                </tr>
				<tr>
                    <td><label>Checkin</label></td>
                    <td><input type="checkbox" name="checkin" id="checkin"></td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align: center;" >
                        <div>
                            <input type="submit" name="them_bv" value="Thêm" >
                            <input type="button" name="huy" value="Hủy" >
                        </div>
                    </td>
                </tr>
            </tbody>
            <tfoot>
              
   
            </tfoot>
        </table>
    </fieldset>
</form>



<?php
 }
require '../layout/footeradmin.inc';
?>